package com.moneyanalyzer.adapter;


import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.moneyanalyzer.R;
import com.moneyanalyzer.model.Category;


public class CategoryAdapter extends BaseAdapter {
	private Context context;
	private List<Category> categorys;
	
	public CategoryAdapter(Context context, List<Category> categorys){
		this.context = context;
		this.categorys = categorys;
	}

	@Override
	public int getCount() {
		return categorys.size();
	}

	@Override
	public Object getItem(int position) {
		return categorys.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Category category = categorys.get(position);
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View itemView = inflater.inflate(R.layout.item_list_categorys, null);
		TextView categoryName = (TextView)itemView.findViewById(R.id.categoryName);
		categoryName.setText(category.getName());	
		return itemView;
	}
	
	public void setMyList(List<Category> categorys) {
		if(categorys != null && categorys.size() > 0){
			this.categorys = categorys;
			
		}else{
			this.categorys = new ArrayList<Category>();
		}
		this.notifyDataSetChanged();
	}

}
